package th;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/24 10:03
 * @description 线程停止方法
 */
public class ThreadStop implements Runnable {

    private boolean flag = true;

    @Override
    public void run() {

        int i = 0;
        while (flag) {
            System.out.println("run...Thread" + i++);
        }
    }

    public void stop() {
        this.flag = false;
    }

    public static void main(String[] args) {

        ThreadStop threadStop = new ThreadStop();
        new Thread(threadStop).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("i = " + i);
            if (i == 900) {
                threadStop.stop();
                System.out.println("thread is stop");
            }
        }
    }

}
